<template>
	<view class="container">
		<view class="search">
			<input
				type="search"
				name=""
				placeholder="请输入公司名称"
				id=""
				v-model="form.company_name"
				@blur="search"
			>
			<image
				src="@/static/images/icon/search.png"
				mode=""
			></image>
		</view>
		<view class="time">
			<uni-datetime-picker
				class="time"
				v-model="range"
				@change="dateChange"
				type="daterange"
			/>
		</view>

		<Compony
			v-for="item,index in comList"
			:key="index"
			:list="item"
		></Compony>
	</view>
</template>

<script>
import Compony from "@/pages/components/compony/compony.vue"
import mixins from "@/mixins/mixins.js"
import {
	Home
} from '@/config/API.js'
export default {
	components: {
		Compony
	},
	mixins: [mixins],
	data () {
		return {
			range: ['2023-06-7', '2023-7-7'],
			comList: [],
			form: {
				limit: 5,
				page: 1,
				company_name: ''
			},
		};
	},
	created () {
		let temp = this.formatTime()
		this.range = temp;
	},
	methods: {
		clear () {
			this.form.page = 1;
			this.comList = [];
		},
		init () {
			Home.indexCompany(this.form).then(res => {
				uni.stopPullDownRefresh()
				this.form.page++;
				this.comList.push(...res.data.items);
				if (res.data.items.length < 1) {
					uni.showToast({
						icon: "none",
						title: "没有更多数据了"
					})
					this.form.page--
				}
			})
		},
		search () {
			this.clear()
			this.init()
		},
		dateChange (res) {
			if (res.length != 2) {
				uni.showToast({
					icon: "error",
					title: "日期需选择范围"
				})
			}
			this.range = res;
			this.clear()
			this.init()
		}
	}
}
</script>
<style>
page {
	background-color: #f4f6f8;
}
</style>
<style lang="scss" scoped>
.time {
	position: fixed;
	top: 140rpx;
	left: 0;
	z-index: 999;
	width: 100%;
}
.container {
	padding-top: 240rpx;
}

.search {
	padding: 37rpx 32rpx 33rpx;
	background: #ffffff;
	border-radius: 0rpx 0rpx 0rpx 0rpx;
	opacity: 1;
	position: fixed;
	top: 0;
	left: 0;
	z-index: 999;

	input {
		width: 686rpx;
		height: 76rpx;
		background: #f4f6f8;
		border-radius: 80rpx 80rpx 80rpx 80rpx;
		opacity: 1;
		padding-left: 88rpx;

		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	image {
		width: 30rpx;
		height: 30rpx;
		position: absolute;
		left: 61rpx;
		top: 60rpx;
	}
}

.time {
	font-size: 28rpx;
	font-family: PingFang SC-Bold, PingFang SC;
	font-weight: bold;
	color: #333333;
}
</style>